<template>
  <div>
    <div>promise小练习</div>
  </div>
</template>
<script setup>
const getId = () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(2);
    }, 2000);
  });
};
const getList = (id) => {
  return new Promise((resolve, reject) => {
    console.log(`获取到id，id为${id},开始准备数据.....`);
    setTimeout(() => {
      resolve({
        code: 0,
        data: [
          { goodsName: "袜子", price: 20 },
          { goodsName: "T恤", price: 25 },
          { goodsName: "牛仔裤", price: 50 },
          { goodsName: "连衣裙", price: 70 },
          { goodsName: "运动鞋", price: 80 },
          { goodsName: "夹克", price: 120 },
          { goodsName: "帽子", price: 15 },
          { goodsName: "围巾", price: 30 },
          { goodsName: "手套", price: 18 },
          { goodsName: "裙子", price: 60 },
          { goodsName: "卫衣", price: 90 },
        ],
      });
    }, 3000);
  });
};
getId()
  .then(
    (result) => {
      console.log(result);
      return getList(result);
    },
    (errorMsg) => {
      console.log(errorMsg);
    }
  )
  .then((result) => {
    console.log("第二个then中的result", result);
    return 4;
  })
  .then((result) => console.log("第三个then中的result", result));
</script>
<style></style>
